from common.utils.toolkit import Log
import subprocess

class Shell:
    @staticmethod
    def exec(cmd, wait=False):
        ret = ""
        Log.d("exec: {}".format(cmd))
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=None, encoding='utf-8', text=True)
        if(wait):
            while(proc.poll() is None):
                for line in proc.stdout:
                    Log.d(line)
                    ret += line
        return ret
